package com.dingwen.treasure.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dingwen.treasure.base.enums.StatusEnum;
import com.dingwen.treasure.model.entity.mybatisplus.BusinessRule;
import com.dingwen.treasure.mybatisplus.mapper.BusinessRuleMapper;
import com.dingwen.treasure.mybatisplus.service.BusinessRuleService;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * @author dingwen
 * @description 针对表【business_rule(JS校验规则业务案例)】的数据库操作Service实现
 * @createDate 2022-08-29 15:27:19
 */
@Service
public class BusinessRuleServiceImpl extends ServiceImpl<BusinessRuleMapper, BusinessRule> implements BusinessRuleService {

    /**
     * 获取所有可用校验规则的字段名称
     *
     * @return {@link Set}<{@link String}>
     */
    @Override
    public Set<String> getAllFieldNames() {
        LambdaQueryWrapper<BusinessRule> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusinessRule::getRuleState, StatusEnum.NORMAL)
                .select(BusinessRule::getFieldName, BusinessRule::getRuleId);
        Set<String> fieldNames = new HashSet<>(16);
        list(queryWrapper)
                .parallelStream()
                .forEach(businessRule -> fieldNames.addAll(businessRule.getFieldNames()));
        return fieldNames;
    }
}




